<?php
/*
+--------------------------------------------------------------------------
|   phpBIZbiz v3.0 full version
|   ========================================
|   by taft@wjl.cn
|   http://www.phpbiz.cn
|   all rights reserved
+---------------------------------------------------------------------------
|
|   > 
|   > 最后修改日期：2005-9-9
|   > 
|
+--------------------------------------------------------------------------
*/
!function_exists('do_login') && exit('Forbidden');
$log = new ad_loginfo;
class ad_loginfo
{
	var $base_url;
		
	function ad_loginfo()
	{
		global $INCOME,$CONF;

		$this -> base_url = $CONF['admin_url']."admin.".$CONF['php_ext'];

		//---------------------------------------
		// Kill globals - globals bad, Homer good.
		//---------------------------------------
		
		$tmp_in = array_merge( $_GET, $_POST, $_COOKIE );
		
		foreach ( $tmp_in as $k => $v )
		{
			unset($$k);
		}
		
	   //---------------------------------------

	   switch ($INCOME['code'])
		{
		   case 'search':
			   $this -> do_search();
		       break;
		   case 'delform':
			   $this -> del_form();
		       break;
		   case 'dodel':
			   $this -> do_del();
		       break;
		   default:
			   $this ->list_form();
		}
	   

	
	}

	function list_form()
	{
	   global $DB,$INCOME,$SKIN,$ADMIN;
	   
	   $DB -> db_query(" SELECT user_id as i, user_account as a FROM biz_admin_user ");

	   while( $re = $DB -> db_fetch_row() )    //query administrator
	   {
		  $list_array[]= array( $re[i], $re[a] );
	   }

	          
	   $ADMIN -> page_title = "后台日志列表";
	   $ADMIN -> page_instruction = "你可以在这里查询，浏览，删除多余的日志信息";

	   $SKIN -> td_header[] = array("","45%");
	   $SKIN -> td_header[] = array("","");

	   $ADMIN ->html .= $SKIN -> table_head("日志查询");

	   $ADMIN ->html .= $SKIN -> form_head();
	   $ADMIN ->html .= $SKIN -> form_input("code","search","hidden");
       
	   $ADMIN ->html .= $SKIN -> table_row( array( "选择管理员",$SKIN->form_droplist( "USER_ID", $list_array )) );

	   $ADMIN ->html .= $SKIN -> form_end("提交查询");

	   $ADMIN ->html .= $SKIN -> table_end();

	   $ADMIN ->html .= $SKIN -> td_spacer();


/*------------display the list ----------------*/
	   
	    $DB -> db_query( "SELECT count(*) as ct FROM biz_admin_log " );
		$row_count = $DB -> db_fetch_row();
  
	    if( $row_count['ct'] <1 )
		          $ADMIN -> error("日志信息丢失！");
		
		$start = $INCOME['st'] ? intval( $INCOME['st'] ) : 0;
		
		$query = "select m.user_account, l.* from biz_admin_log l, biz_admin_user m WHERE m.user_id = l.user_id  ORDER BY l.log_time DESC LIMIT $start, 10 " ;
        
		$DB -> db_query( $query );
		
		$pages = $SKIN->build_pagelinks( array('TOTAL_POSS'  => $row_count['ct'],
											   'PER_PAGE'    => 10,
											   'CUR_ST_VAL'  => $start,
											   'L_SINGLE'    => "一页",
											   'L_MULTI'     => "页：",
											   'BASE_URL'    => $this->base_url."?act=log"."&code={$INCOME['code']}"
											   )
											);

       	$SKIN->td_header[] = array( "用户名"            , "20%" );
		$SKIN->td_header[] = array( "执行操作"        , "35%" );
		$SKIN->td_header[] = array( "操作时间"         , "17%" );
		$SKIN->td_header[] = array( "IP地址"             , "15" );
		$SKIN->td_header[] = array( "URL","");
 	   
        $ADMIN ->html .= $SKIN -> table_head("日志列表（共$row_count[ct]笔）");

		while( $record = $DB -> db_fetch_row() )
		{
			$ADMIN -> html .= $SKIN -> table_row(
			                  array("<b><center>{$record[user_account]}</center></b>", 
			                        "{$record[log_content]}",
			                        "<center>{$record[log_time]}</center>",
			                        "<center>{$record[log_ip]}</center>",
									"?act={$record[act]}&code={$record[code]}"
			                        ));
		}

		$ADMIN->html .= $SKIN->td_basic($pages, 'right', 'pformstrip');
		$ADMIN->html .= $SKIN->table_end();
		
		$ADMIN->output();
	}

	function do_search()
	{
		global $INCOME,$DB,$ADMIN,$SKIN;

        $id = intval( $INCOME[USER_ID] );
		$DB -> db_query( "SELECT count(*) as ct FROM biz_admin_log WHERE user_id = $id " );
		$row_count = $DB -> db_fetch_row();
  
	    if( $row_count['ct'] <1 )
		          $ADMIN -> error("日志信息丢失！");
		
		$start = $INCOME['st'] ? intval( $INCOME['st'] ) : 0;
		
		$query = "select m.user_account,  l.* from biz_admin_log l, biz_admin_user m WHERE m.user_id = l.user_id AND l.user_id = $id ORDER BY l.log_time DESC LIMIT $start, 15 " ;
        
		$DB -> db_query( $query );
				
		$page_query = "&USER_ID=".$id;

		$pages = $SKIN->build_pagelinks( array('TOTAL_POSS'  => $row_count['ct'],
											   'PER_PAGE'    => 15,
											   'CUR_ST_VAL'  => $start,
											   'L_SINGLE'    => "一页",
											   'L_MULTI'     => "页：",
											   'BASE_URL'    => $this->base_url."?act=log"."&code={$INCOME['code']}".$page_query
											   )
											);

       	$SKIN->td_header[] = array( "用户名"            , "20%" );
		$SKIN->td_header[] = array( "执行操作"        , "35%" );
		$SKIN->td_header[] = array( "操作时间"         , "17%" );
		$SKIN->td_header[] = array( "IP地址"             , "%" );
		$SKIN->td_header[] = array( "URL"              ,"");
 	   
        $ADMIN ->html .= $SKIN -> table_head("日志搜索结果（共$row_count[ct]笔）");

		while( $record = $DB -> db_fetch_row() )
		{
			$ADMIN -> html .= $SKIN -> table_row(
			                  array("<b><center>{$record[user_account]}</center></b>", 
			                        "{$record[log_content]}",
			                        "<center>{$record[log_time]}</center>",
			                        "<center>{$record[log_ip]}</center>",
			                        "?act={$record[act]}&code={$record[code]}"
			                        ));
		}

		$ADMIN->html .= $SKIN->td_basic($pages, 'right', 'pformstrip');
		$ADMIN->html .= $SKIN->table_end();
		
		$ADMIN->output();

	}

	function del_form()
	{
		global $ADMIN,$SKIN,$DB,$INCOME;

		$ADMIN -> page_title = "后台日志清理";

		$ADMIN -> page_instruction = "请小心操作";

		$s = $DB -> db_query( " SELECT * FROM biz_admin_user" );
		
		$SKIN -> td_header[] = array("管理员","30%");
		$SKIN -> td_header[] = array("该管理员的日志数目","40%");
		$SKIN -> td_header[] = array("移除该管理员的所有日志","30%");

		$ADMIN -> html .= $SKIN -> table_head();

		while( $res = $DB-> db_fetch_row($s) )
		{
			$DB -> db_query( "SELECT count(*) as ct FROM biz_admin_log WHERE user_id = $res[user_id] " );
			$count = $DB -> db_fetch_row();
            if( $count[ct] )
     			$ADMIN -> html .= $SKIN -> table_row( array("<b><center>{$res[user_account]}</center></b>","<center>{$count[ct]}</center>","<center><a href='{$this -> base_url}?act=log&code=dodel&USER_ID={$res[user_id]}'>移 除</a></center>") );
		}

		$ADMIN -> html .= $SKIN -> table_end();
        $ADMIN -> output();
	}

	function do_del()
	{
		global $DB,$ADMIN,$INCOME;

		$id = intval( $INCOME[USER_ID] );

		$DB -> db_query( "DELETE FROM biz_admin_log WHERE user_id = $id " );
		$DB -> db_query( "SELECT user_account as a FROM biz_admin_user WHERE user_id = $id" );
		$u = $DB -> db_fetch_row();

		$ADMIN -> record_log( "清除管理员‘{$u[a]}’的所有日志");
		$ADMIN -> done_screen( "该管理员日志已清除", "查看日志", "act=log&code=list" );
	}

}




?>